<template>
  <div>
    <el-table :data="tolist" height="250" border style="width: 100%">
     
      <el-table-column prop="name" label="姓名" width="180"></el-table-column>
      <el-table-column prop="address" label="地址"></el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :page-sizes="[5, 6, 7]"
      :page-size="100"
      layout="total, sizes, prev, pager, next, jumper"
      :total="tableData.length"
    ></el-pagination>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  data () {
    return {
      tableData: [],
      tolist: [],
      num: 5
    }
  },
  methods: {
    handleSizeChange (val) {
      this.tolist = []
      this.num = val
      for (let a = 0; a < val; a++) {
        this.tolist.push(this.tableData[a])
      }
    },
    handleCurrentChange (val) {
      console.log(val)
      this.tolist = []
      let xian = this.num * val
      if (xian > this.tableData.length) {
        xian = this.tableData.length
      }
      let qian = this.num * (val - 1)
      for (let a = qian; a < xian; a++) {
        this.tolist.push(this.tableData[a])
      }
    },
  },
  mounted () {
    axios
      .get('http://localhost:8080/shoplist.json')
      .then((res) => {
        console.log(res.data)
        this.tableData = res.data
        // 分页初始化 初始显示的数量
        for (var a = 0; a < 5; a++) {
          this.tolist.push(this.tableData[a]);
        }
      })
      .catch((err) => {
        console.error(err)
      })
  },
}
</script>
